<template>
	<view class="my-star">
		<image :src="`../../static/images/star-${i}.png`" style="width: 32rpx;" mode="widthFix" v-for="(i,k) in list" :key="k"></image>
	</view>
</template>

<script>
	export default {
		props: {
			score: {
				type: String,
				default: ''
			}
		},
		data() {
			return {
				list: []
			};
		},
		mounted() {
			this.init();
		},
		methods: {
			init() {
				let arr = [0, 0, 0, 0, 0];
				
				let num = Number(this.score);
				let full = Math.floor(num);
				let half = num - full;
				
				for (let i = 0; i < full; i++) {
				  arr[i] = 1;
				}
				if (half > 0.25 && half < 0.75) {
				  arr[full] = 0.5;
				} else if (half > 0.75) {
				  arr[full] = 1;
				}
				this.list = arr
			}
		}
	}
</script>

<style lang="scss">
	.my-star {
		display: flex;
		align-items: center;
		image {
			margin-right: 4rpx;
		}
	}
</style>
